//
//  PiecesRecordCell.m
//  J智现场
//
//  Created by song on 2018/1/26.
//  Copyright © 2018年 王长飞. All rights reserved.
//

#import "MoreGoodsCell.h"

@interface MoreGoodsCell()
{
    UIImageView *pictureImg;
    UILabel *goodsnamelab ;
    UILabel *promotionPriceLab ;
    UILabel *originalPriceLab ;
}
@end

@implementation MoreGoodsCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath*)indexPath
{
    NSString *cellID = [NSString stringWithFormat:@"cellID%zd%zd",indexPath.section,indexPath.row];
    MoreGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MoreGoodsCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundView = nil ;
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self buildUI];
    }
    return self;
}

- (void)buildUI
{
    pictureImg = [[UIImageView alloc]initWithFrame:CGRectMake(12, 10, 100, 100)];
    [self addSubview:pictureImg];
    
    goodsnamelab = [[UILabel alloc]initWithFrame:CGRectMake(pictureImg.right+8, 15, SCREEN_WIDTH-pictureImg.right-80-12, 50)];
    goodsnamelab.font = KFontSmall;
    goodsnamelab.textColor = kTitleColor_black;
    goodsnamelab.numberOfLines = 3;
    [self addSubview:goodsnamelab];
    
    promotionPriceLab = [[UILabel alloc] initWithFrame:CGRectMake(pictureImg.right+8, 85, 100, 20)];
    promotionPriceLab.textColor = [UIColor redColor];
    promotionPriceLab.font = kFontMidden;
    [self addSubview:promotionPriceLab];
    
    originalPriceLab = [[UILabel alloc] initWithFrame:CGRectMake(promotionPriceLab.right, promotionPriceLab.top+5, 150, 12)];
    originalPriceLab.font = kFontMimi;
    originalPriceLab.textColor = kTitleColor_light;
    [self addSubview:originalPriceLab];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(5, 119, SCREEN_WIDTH-10, 0.5)];
    line.backgroundColor = UIColorFromRGB1(0xE5B580);
    [self addSubview:line];
    
}

- (void)setModel:(MoreGoodsDataList *)model{

    _model = model;

    [pictureImg sd_setImageWithURL:[NSURL URLWithString:model.indexPic]];
    goodsnamelab.text = model.title;
    goodsnamelab.height = [PublicUtils getStringSize:goodsnamelab.text Width:goodsnamelab.width Font:goodsnamelab.font].height;
    
    promotionPriceLab.text = [NSString stringWithFormat:@"¥%@",model.promotionPrice];
    float width = [PublicUtils getLabelWidthWithString:promotionPriceLab.text font:promotionPriceLab.font];
    promotionPriceLab.width = width+10;

    NSString *originalPrice = model.originalPrice;
    NSUInteger length = [originalPrice length];
    originalPriceLab.left = promotionPriceLab.right;
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:originalPrice];
    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, [originalPrice length])];
    [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, length)];
    [originalPriceLab setAttributedText:attri];
}

@end
